<template>
  <div class="page-right">
    <ChangeSetType v-model="setType" />
    <!-- 页面设置 -->
    <div v-show="setType === 1">
      <SetPageInfo />
    </div>
    <!-- 组件设置 -->
    <div v-show="setType === 2">
      <ComTitle :title="currentComponent && currentComponent.name || '组件设置'"/>
      <!-- 生效时间 -->
      <ComValidTime v-if="currentComponent" v-model="currentComponent.data.validTime"/>
      <component 
      :is="currentComponent.data.component"
      v-if="currentComponent"
      :parmes="currentComponent.data"
      @editComponent="editComponent" 
      />
    </div>
  </div>
</template>

<script>
import SetPageInfo from './components/SetPageInfo'
import ChangeSetType from './components/ChangeSetType'
import { dynamicComponents } from '@/utils'
import ComValidTime from '@/components/BasicUi/ComValidTime'
import ComTitle from '@/components/BasicUi/ComTitle.vue'
import {mapState,mapActions} from 'vuex'
export default {
  components: { ChangeSetType, SetPageInfo, ...dynamicComponents(), ComValidTime,ComTitle },
  data() {
    return {

    };
  },
  computed: {
    setType: {
      get: function () {
        return this.$store.state.setType
      },
      set: function (val) {
        this.$store.commit('SET_SETTYPE', val)
      }
    },
    currentComponent() {
      //拿到数据里的组件
      const componentList = this.$store.state.pageData.componentList
      //先判断有没有数据 有的话 通过find查找数据 没有的话 返回null
      console.log(componentList,'commmmmmm');
      return componentList && componentList.length > 0 ? componentList.find(item => item.id === this.$store.state.activeComponentId) : null
    }
  },

  mounted() {
      
  },

  methods: {
    ...mapActions(['pageChange']),
    //接收子组件回传的数据并更新store中的pageData
    editComponent(data){
      //调用修改数据编辑的方法
         this.pageChange({
          type:'edit',
          id:this.$store.state.activeComponentId,
          //子组件更新后传回来的数据
          data
         })
    }
  },
};
</script>

<style lang="less">
@import url("~@/styles/icon.less");

.page-right {
  position: absolute;
  top: 56px;
  right: 0;
  bottom: 0;
  width: 376px;
  padding-bottom: 50px;
  overflow-x: hidden;
  overflow-y: auto;
  background: #fff;
}

// 组件配置模块
.com-group {

  // slide 滑块
  .el-slider {
    width: 95%;

    .el-slider__input {
      width: 60px;
    }

    .el-slider__runway {
      margin-right: 80px;
    }
  }

  // 单选框
  .el-radio {
    line-height: 30px;
    color: #323233;
  }
}

// 右上角删除样式
.up-pic-item-delete {
  position: absolute;
  cursor: pointer;
  font-size: 20px;
  right: -10px;
  top: -10px;
  color: #bbb;
  background: #fff;
  border-radius: 50%;
  visibility: hidden;
  z-index: 2;

  &:hover {
    color: #aaa;
  }
}
</style>